﻿Imports System.IO

Namespace EyeOpen.IO.Test

	Friend Class TestDirectoryInfo
		Implements IDirectoryInfo
		Private ReadOnly directoryList As New HashSet(Of TestDirectoryInfo)()

		Private ReadOnly fileList As New HashSet(Of FileInfo)()

		Public Sub New(ByVal fullName As String)
			privateFullName = fullName
		End Sub

		Public Sub New(ByVal parent As TestDirectoryInfo, ByVal name As String)
			Me.Parent = parent

			privateFullName = Path.Combine(parent.FullName, name)
		End Sub

		Public Property Parent() As TestDirectoryInfo

		Private ReadOnly privateFullName As String
		Public ReadOnly Property FullName() As String Implements IDirectoryInfo.FullName
			Get
				Return privateFullName
			End Get
		End Property


		Public Function GetFiles(ByVal fileName As String) As IEnumerable(Of FileInfo) Implements IDirectoryInfo.GetFiles
			Return fileList.Where(Function(f) f.Name = fileName)
		End Function

		Public Function GetDirectories() As IEnumerable(Of IDirectoryInfo) Implements IDirectoryInfo.GetDirectories
			Return directoryList
		End Function

		Public Function AddDirectory(ByVal name As String) As TestDirectoryInfo
			Dim directoryInfo = New TestDirectoryInfo(Me, name)

			directoryList.Add(directoryInfo)

			Return directoryInfo
		End Function

		Public Function AddFile(ByVal fileName As String) As TestDirectoryInfo
			Dim fileInfo = New FileInfo(Path.Combine(FullName, fileName))

			fileList.Add(fileInfo)

			Return Me
		End Function

		Public Overrides Function ToString() As String
			Return FullName
		End Function
	End Class
End Namespace